<?php
$sch = new Swoole\Coroutine\Scheduler;
$sch->add(function () use ($sch) {
   $mysql = new Swoole\Coroutine\MySQL();
   $mysql->connect([
      'host' => '127.0.0.1',
      'port' => 3306,
      'user' => 'jdladmin',
      'password' => '123456',
      'database' => 'users',
      'charset' => 'utf8',
      'fetch_mode'  => true,  //开启fetch模式, 可与pdo一样使用fetch/fetchAll逐行或获取全部结果集(4.0版本以上)
   ]);

   $mysql->query("insert into users(`username`,`age`) values ('jdl',11)");
   $res = $mysql->query("select * from user");
   var_dump($res);

    $stmt = $mysql->prepare('SELECT * FROM users');
    $stmt->execute();
    while ($ret = $stmt->fetch()) {
        var_dump($ret);
    }
});
$sch->start();